﻿@using PagedList
@model PagedList.IPagedList<ShenLanCMS.Models.Post>
@{
    var result = "";
    if (ViewData["keyword"] != null)
    {
        result = ViewBag.Title = ViewData["keyword"].ToString() + "的搜索结果";
    }
    else
    {
        ViewBag.Title = "文章搜索";
    }
    Layout = "~/Views/Shared/_PublicLayout.cshtml";
}
<fieldset>
    <legend>文章搜索</legend>
    <br />
    <div>
        请输入关键词<input type="text" name="skey" id="skey" />
        <input id="btnSearch" type="submit" value="搜索" />
    </div>
    <br />
    <div>
        @ViewData["result"]
    </div>
    <br />
    <div>
        @foreach (var item in Model)
        {
            <li>[ <a href="/post/bytype/@item.PostTypeID">@item.GetPostType().TypeName</a> ] <a href="/post/view/@item.PostID" title="@item.Title" target="_blank">@item.Title</a>(点击:@item.Click)</li>
        }
    </div>
    <br />
    <div style="width: auto; height: 30px; margin-top: 10px; text-align: left;">
        @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
        / @Model.PageCount
        &nbsp;
        @if (Model.HasPreviousPage)
        {
            @Html.ActionLink("首页", ViewData["actionName"].ToString(), new { page = 1, keyword = ViewData["keyword"] })
            @Html.Raw("&nbsp;");
            @Html.ActionLink("< 上一页", ViewData["actionName"].ToString(), new { page = Model.PageNumber - 1, keyword = ViewData["keyword"] })
        }
        else
        {
            @Html.Raw("首页&nbsp;&nbsp;上一页")
        }
        &nbsp;
        @if (Model.HasNextPage)
        {
            @Html.ActionLink("下一页 >", ViewData["actionName"].ToString(), new { page = Model.PageNumber + 1, keyword = ViewData["keyword"] })
            @Html.Raw("&nbsp;");
            @Html.ActionLink("尾页", ViewData["actionName"].ToString(), new { page = Model.PageCount, keyword = ViewData["keyword"] })
        }
        else
        {
            @Html.Raw("下一页&nbsp;&nbsp;尾页")
        }
    </div>
</fieldset>
<script type="text/javascript">
    function search() {
        var skey = $("#skey").val();
        if (skey == "") {
            alert("请输入关键词");
            return false;
        }
        window.location.href = "?keyword=" + skey;
    }
    $("#btnSearch").click(function () {
        search();
    });
    document.onkeydown = function (event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            search();
        }
    } 
</script>
 